package com.pengshun.modules.api.petrol;

import com.fasterxml.jackson.annotation.JsonView;
import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.order.service.dto.MerchantOrderDto;
import com.pengshun.modules.api.petrol.service.JyPetrolStationOrderService;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationOrderDto;
import com.pengshun.modules.api.petrol.service.dto.JyPetrolStationProductListDto;
import com.pengshun.modules.api.petrol.service.para.JyPetrolStationOrderPara;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.common.ReslutView;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/6/30
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "加油订单管理")
@RequestMapping("/api/petrol/order")
public class JyPetrolStationOrderController {

    private final JyPetrolStationOrderService orderService;

    @ApiOperation(value = "下单")
    @PostMapping(value = "/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "payWay", value = "支付方式(1油气卡支付2余额支付3微信支付4支付支付)", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "payPass", value = "支付密码", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "stationAmount", value = "加油金额", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "realAmount", value = "实付金额", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "petrolStationGunId", value = "加油站枪号id", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "gunName", value = "枪号名称", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "carOwnerNum", value = "车牌号", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "carOwnerId", value = "车牌id", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "stationNum", value = "加油油量", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "discountsAmount", value = "优惠金额", dataType = "int",required = true, paramType = "query"),
            @ApiImplicitParam(name = "petrolStationProductId", value = " 加油站商品id", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @Authorization
    @NoRepeatSubmit
    public BaseResult add(@ApiIgnore @CurrUserInfo User user, @ApiIgnore JyPetrolStationOrderPara para) throws Exception {
        para.setBuyUserId(user.getId());
        BaseResult res = orderService.add(para);
        return res;
    }

    @ApiOperation(value = "加油订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/list", produces = "application/json; charset=utf-8")
    @Authorization
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationOrderDto.class)
    })
    public BaseResult orderList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = orderService.orderList(para);
        return res;
    }
    @ApiOperation(value = "加油订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "petrolStationOrderId", value = "订单id", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/detil", produces = "application/json; charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 0, message = "OK", response = JyPetrolStationOrderDto.class)
    })
    public BaseResult detil(Long petrolStationOrderId) throws Exception {
        BaseResult res = orderService.detil(petrolStationOrderId);
        return res;
    }

}
